package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.AxiConfig;
import com.sailfish.springbootdemo.pojo.db2.AxiData;
import com.sailfish.springbootdemo.pojo.db2.PcbApproveConfig;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface AxiDataDao {

    @Results(id = "axiDataResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "product_level", property = "productLevel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_name", property = "productName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_line", property = "productLine", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_code", property = "pcbCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "panel_code", property = "panelCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "panel_name", property = "panelName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_status", property = "productStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "board_complexity", property = "boardComplexity", jdbcType = JdbcType.VARCHAR),
            @Result(column = "first_pass_yield", property = "firstPassYield", jdbcType = JdbcType.VARCHAR),
            @Result(column = "test_rate", property = "testRate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "test_project", property = "testProject", jdbcType = JdbcType.VARCHAR),
            @Result(column = "table_type", property = "tableType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_type", property = "productType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_time_refresh", property = "updateTimeRefresh", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "project_version", property = "projectVersion", jdbcType = JdbcType.VARCHAR),
            @Result(column = "is_delete", property = "isDelete", jdbcType = JdbcType.INTEGER),
            @Result(column = "need_sendmail", property = "needSendmail", jdbcType = JdbcType.INTEGER),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
    })
    /*
     * 查询单个
     */
    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.AXI_DATA +
            "<where> " +
            " and (need_sendmail is null or need_sendmail = 1) " +
            "</where> " +
            "</script>")
    List<AxiData> getNeedSendMail();

    @Select("<script> " +
            "select id,product_level,product_name,product_line,pcb_code,panel_code,panel_name,product_status,board_complexity,first_pass_yield,test_rate,test_project,remark,table_type,product_type,create_time,create_user,update_time,update_user,update_time_refresh,project_version,is_delete,need_sendmail " +
            "from " + DB2TableName.AXI_DATA +
            "</script>")
    @ResultMap(value = "axiDataResultMap")
    List<AxiData> getAll();

    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.AXI_DATA +
            "<where> " +
            "  (table_type = 'CT-TB1') " +
            "  and (is_delete != 1 OR is_delete IS NULL)" +
            "  <if test='boardComplexity != null'>" +
            "  and board_complexity &lt;= #{boardComplexity}" +
            "  </if>" +
            "</where> " +
            "</script>")
    @ResultMap(value = "axiDataResultMap")
    List<AxiData> getSfcCodeList(@Param("boardComplexity") Double boardComplexity);

    @Update("<script> " +
            "update " + DB2TableName.AXI_DATA +
            "<set> " +
            " need_sendmail = 2" +
            "</set> " +
            "where id = #{id}" +
            "</script>")
    Integer update(AxiData param);
}
